
import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import moment from 'moment';
import Factory from '../factory';
import * as datetime from '../../utils/datetime'
import dataEditCreate from '../addons/DataEdit'
import dataTableCreate from '../addons/DataTable'
import * as menuService from '../../services/menus'
import * as com from '../../utils/common';
import YJRDS from './YJRDS'
const daoName = "ZTXMCMX";
const ButtonGroup = Button.Group;
const columns = [
    { title: '到期日', width: 120, sorter: true, render: data => datetime.format(data.Dqr, "yyyy-MM-dd"), key: 'Dqr', dispaly: true, filter: true },
    { title: '出票日', width: 120, sorter: true, render: data => datetime.format(data.Cpr, "yyyy-MM-dd"), key: 'Cpr', dispaly: true, filter: true },
    { title: '转贴现日', width: 120, sorter: true, render: data => datetime.format(data.Ztxr, "yyyy-MM-dd"), key: 'Ztxr', dispaly: true, filter: true },
    { title: '计息到期日', width: 120, sorter: true, render: data => datetime.format(data.Jxdqr, "yyyy-MM-dd"), key: 'Jxdqr', dispaly: true, filter: true },
    { title: '买入日期', width: 120, sorter: true, render: data => datetime.format(data.Mrrq, "yyyy-MM-dd"), key: 'Mrrq', dispaly: true, filter: true },
    { title: '实收金额', className: 'column-money', render: data => com.formatNumber(data.Ssje), key: 'Ssje', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '票面金额', className: 'column-money', render: data => com.formatNumber(data.Pmje), key: 'Pmje', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '应付利息', dataIndex: 'Yflx', key: 'Yflx', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '利率', dataIndex: 'Lilu', key: 'Lilu', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '计息天数', dataIndex: 'Jxts', key: 'Jxts', width: 180, sorter: true, dispaly: true, filter: true },
    { title: '票据号码', dataIndex: 'Pjhm', key: 'Pjhm', width: 240, sorter: true, dispaly: true, filter: true },
    { title: '出票人名称', dataIndex: 'Cprmc', key: 'Cprmc', width: 260, sorter: true, dispaly: true, filter: true },
    { title: '承兑人', dataIndex: 'Cnr', key: 'Cnr', width: 300, sorter: true, dispaly: true, filter: true },
    { title: '收款人', dataIndex: 'Skr', key: 'Skr', width: 300, sorter: true, dispaly: true, filter: true },
    { title: '票据介质', dataIndex: 'Pjjz', key: 'Pjjz', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '归属机构ID', dataIndex: 'Gsjg', key: 'Gsjg', width: 260, sorter: true, dispaly: true, filter: true },
    { title: '转贴现种类', dataIndex: 'Ztxzl', key: 'Ztxzl', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴入方名称', dataIndex: 'Trfmc', key: 'Trfmc', width: 300, sorter: true, dispaly: true, filter: true },
    { title: '贴入方大额行号', dataIndex: 'Trfdexh', key: 'Trfdexh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴入方账号', dataIndex: 'Trfzh', key: 'Trfzh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴入方组织机构代码号', dataIndex: 'Trfzzjgdmh', key: 'Trfzzjgdmh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '标准贴入方组织机构代码', dataIndex: 'Bztrfzzjgdm', key: 'Bztrfzzjgdm', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴出方名称', dataIndex: 'Tcfmc', key: 'Tcfmc', width: 230, sorter: true, dispaly: true, filter: true },
    { title: '标准贴出方客户名称', dataIndex: 'Bztcfmc', key: 'Bztcfmc', width: 230, sorter: true, dispaly: true, filter: true },
    { title: '贴出方大额行号', dataIndex: 'Tcfdexh', key: 'Tcfdexh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴出方账号', dataIndex: 'Tcfzh', key: 'Tcfzh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '贴出方组织机构代码号', dataIndex: 'Tcfzzjgdmh', key: 'Tcfzzjgdmh', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '标准贴出方组织机构代码', dataIndex: 'Bztcfzzjgdm', key: 'Bztcfzzjgdm', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '客户经理', dataIndex: 'Khjl', key: 'Khjl', width: 120, sorter: true, dispaly: true, filter: true },
];
const controls = [
    { name: 'Dqr', required: true, type: 'text', label: '到期日', min: 2, max: 30, grid: 12 / 24 },
    { name: 'Cpr', required: true, type: 'text', label: '出票日', grid: 12 / 24 },
    { name: 'Ztxr', required: true, type: 'text', label: '转贴现日', grid: 12 / 24 },
    { name: 'Jxdqr', required: true, type: 'text', label: '计息到期日', grid: 12 / 24 },
    { name: 'Mrrq', required: true, type: 'text', label: '买入日期', grid: 12 / 24 },
    { name: 'Ssje', required: true, type: 'alphanum', label: '实收金额', grid: 12 / 24 },
    { name: 'Pmje', required: true, type: 'alphanum', label: '票面金额', grid: 12 / 24 },
    { name: 'Yflx', required: true, type: 'alphanum', label: '应付利息', grid: 12 / 24 },
    { name: 'Lilu', required: true, type: 'alphanum', label: '利率', grid: 12 / 24 },
    { name: 'Jxts', required: true, type: 'alphanum', label: '计息天数', grid: 12 / 24 },
    { name: 'Pjhm', required: true, type: 'text', label: '票据号码', grid: 12 / 24 },
    { name: 'Cprmc', required: true, type: 'text', label: '出票人名称', grid: 12 / 24 },
    { name: 'Cnr', required: true, type: 'text', label: '承兑人', grid: 12 / 24 },
    { name: 'Skr', required: true, type: 'text', label: '收款人', grid: 12 / 24 },
    { name: 'Pjjz', required: true, type: 'text', label: '票据介质', grid: 12 / 24 },
    { name: 'Gsjg', required: true, type: 'text', label: '归属机构ID', grid: 12 / 24 },
    { name: 'Ztxzl', required: true, type: 'text', label: '转贴现种类', grid: 12 / 24 },
    { name: 'Trfmc', required: true, type: 'text', label: '贴入方名称', grid: 12 / 24 },
    { name: 'Trfdexh', required: true, type: 'text', label: '贴入方大额行号', grid: 12 / 24 },
    { name: 'Trfzh', required: true, type: 'text', label: '贴入方账号', grid: 12 / 24 },
    { name: 'Trfzzjgdmh', required: true, type: 'text', label: '贴入方组织机构代码号', grid: 12 / 24 },
    { name: 'Bztrfzzjgdm', required: true, type: 'text', label: '标准贴入方组织机构代码', grid: 12 / 24 },
    { name: 'Tcfmc', required: true, type: 'text', label: '贴出方名称', grid: 12 / 24 },
    { name: 'Bztcfmc', required: true, type: 'text', label: '标准贴出方客户名称', grid: 12 / 24 },
    { name: 'Tcfdexh', required: true, type: 'text', label: '贴出方大额行号', grid: 12 / 24 },
    { name: 'Tcfzh', required: true, type: 'text', label: '贴出方账号', grid: 12 / 24 },
    { name: 'Tcfzzjgdmh', required: true, type: 'text', label: '贴出方组织机构代码号', grid: 12 / 24 },
    { name: 'Bztcfzzjgdm', required: true, type: 'text', label: '标准贴出方组织机构代码', grid: 12 / 24 },
    { name: 'Khjl', required: true, type: 'text', label: '客户经理', grid: 12 / 24 },
]
const DataTable = dataTableCreate(daoName);
class ZTXMCMXS extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID" }
        });
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20 }
        });
        this.loadOptionData();
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showModelHandler(isAdd) {
        let key = null
        if (!isAdd) {
            const len = this.props.selectedRowKeys.length;
            if (len === 0) {
                message.info('请选择要编辑的行，如果选择了多行，则使用最后一次选择！');
                return;
            }
            key = this.props.selectedRowKeys[len - 1]
        }
        this.props.dispatch({
            type: `${daoName}/openEdit`,
            payload: { key }
        });
    }
    hideEditHandler() {
        if (this.state.dataChange) {
            this.props.dispatch({
                type: `${daoName}/reload`,
                payload: { daoName },
            });
            this.state.dataChange = false;
        }
        this.props.dispatch({
            type: `${daoName}/hideEdit`
        });
    };


    render() {
        let { showEdit, record } = this.props
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        <ButtonGroup style={{ zIndex: 0 }}>
                            <Button onClick={this.showModelHandler.bind(this, false)}>业绩认定</Button>
                        </ButtonGroup>
                    </div>
                    <Modal title={record.Pjhm + "业绩分配" + daoName} width={700} visible={showEdit} onCancel={this.hideEditHandler.bind(this)}>
                        <YJRDS ywid={record.ID} />
                    </Modal>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} />
                </div>
            </div>
        )
    }
}
function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    return {
        showEdit,
        selectedRowKeys,
        keyName,
        record
    }
}
ZTXMCMXS = connect(mapStateToProps)(ZTXMCMXS)
export default ZTXMCMXS;
let render = (props) => React.createElement(ZTXMCMXS, props);

let f = new Factory()
f.set("ZTXMCMXS", render)
